/**
 * Licensed under the Apache License Version 2.0.
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package net.interknit.knitter.client.java;

import net.interknit.knitter.client.layout.ArrayEl;

/**
 *
 */
public class JavaArraySourceWriter extends JavaTypeSourceWriter
{
	@Override
	protected void writeCode(String packageName)
	{
		if(! "".equals(packageName.trim()))
			println("package " + packageName + ";");

		println("import javax.xml.bind.annotation.XmlRootElement;");

		print("@XmlRootElement(name = \"" + getTypeEl().getName() + "\")");
		print("public class " + unqualifiedClassName());
		print("{");

		String pname = "array";
		String ptype = JavaSourceWriterUtils.toJavaType(((ArrayEl) getTypeEl()).getComponentType()) + "[]";

		print(JavaSourceWriterUtils.fieldDeclarationSource(pname, ptype));

		print("");
		print(JavaSourceWriterUtils.getterSource(pname, ptype));

		print("");
		print(JavaSourceWriterUtils.setterSource(pname, ptype));

		print("");
		print("\t" + "public String toString()");
		print("\t" + "{");
		print("\t" + "\t" + "return");
		print("\t" + "\t" + "\t" + "\"" + pname + ": \" + " + "\"[\" + java.util.Arrays.toString(this." + pname + ") + \"]\"");
		print("\t" + "\t" + ";");
		print("\t" + "}");
		print("");

		print("}");
	}
}
